#pragma once
#ifndef SNAKE_H
#define SNAKE_H
#include <QWidget>
#include <qqueue.h>

enum Role
{
	NOTHING, SNAKEBODY, SNAKEHEAD, WALL, FOOD
};

enum Direction
{
	LEFT, RIGHT, UP, DOWN
};

class Snake : public QWidget
{
	Q_OBJECT

public:
	Snake(QWidget* parent, int cellNum, int cellLen);
	~Snake();
	virtual void keyEvent(QKeyEvent* event);
	virtual void init();

	void initWindow(int cellNum, int cellLen);

protected:
	int cellNumX, cellNumY;
	int cellLengthX, cellLengthY;
	Role** board;

	Direction direct, newDirect;
	QQueue<QPoint> snake;

	QTimer* timer;
	virtual void initGame();
	virtual void initCurrentPlayer();
	virtual void generateFood();

	virtual void startGameLoop();
	virtual void doKeyEvent();
	virtual void doGameLogic();
	virtual void updateCurrentPlayer();
	virtual void renderGameFrame();
	virtual void overGame();

	virtual void paintEvent(QPaintEvent* event);

protected slots:
	virtual void loopGame();
};

#endif SNAKE_H
